// var i = 10;
// var f = false;
// var d = 3.14;
// alert(i+d);

//获取页面上的登录按钮
var btn = document.getElementById('btn-login');
//为按钮绑定一个点击事件
btn.addEventListener('click',function(){

	login();
	
	
});
function keyListener(e){
	console.log(e);
	if(e.keyCode == 13){
		login();
	}
}
 
document.onkeydown=keyListener;

function login(){
	
	//获取用于输入账号密码的两个输入框的值
	var name = document.getElementById('name').value;
	var pwd = document.getElementById('pwd').value;
	//校验是否输入账号密码
	if(name.length < 1){
		layer.msg('请输入账号！');
		return false;
	}
	if(pwd.length < 1){
		layer.msg('请填写密码');
		return false;
	}
	/*//提交表单
	document.forms[0].submit();*/
	 
 	
	$.ajax({
		type:"post",
		url:"/sams/user/login",
		data:"username="+name+"&password="+encodeURIComponent(pwd)+"&time="+new Date().toString(),
		dataType:"JSON",
		success:function(data){
		 
		      if(data.status==200){
		    	  //登录成功
		    	  layer.msg(data.msg);
		    	  location.href="/sams/admin_index.jsp";
		      }else{
		    	  layer.msg(data.msg);
		      }
		}
		
	});
}
